// 通过rollup打包
// 获取打包文件
//1 引入相关依赖
const ts = require('rollup-plugin-typescript2') //解析ts，
const json = require('@rollup/plugin-node-resolve') // 解析json
const resolvePlugin = require("@rollup/plugin-node-resolve") //解析第三方插件
const path = require('path') // 处理路径
// 2 获取文件路径
let packagesDir = path.resolve(__dirname, "packages");
console.warn("目录", packagesDir, process.env.TARGET);
// 2.1 获取需要打包的包
let packageDir = path.resolve(packagesDir, process.env.TARGET)
// console.warn("子包", packageDir)
const resolve = p => path.resolve(packageDir, p);
const pkg = require(resolve("package.json"));
const packageOptions = pkg.buildOptions || {};
const name = path.basename(packageDir)
// console.warn(pkg, 8888);
const outputOptions = {
    "esm-bundler": {
        file: resolve(`dist/${name}.esm-bundler.js`),
        format: "es"
    },
    "cjs": {
        file: resolve(`dist/${name}.cjs.js`),
        format: "cjs"
    },
    "global": {
        file: resolve(`dist/${name}.global.js`),
        format: "iife"
    }
}
const options = pkg.buildOptions;
// console.warn("options",outputOptions,options);
function createConfig(format, output) {
    output.name = options.name;
    output.sourcemap = true;
    // 生成rollup配置
    return {
        input:resolve("src/index.ts"), //导入文件
        output,
        plugins:[
            json(),
            ts({tsconfig:path.resolve(__dirname,'tsconfig.json')}),
            resolvePlugin()
        ]
    }
}
const opt= options.formats.map(format => createConfig(format, outputOptions[format]))
// console.warn("opt",opt)
module.exports= opt